<?php
session_start();
date_default_timezone_set("America/Sao_Paulo");
setlocale(LC_ALL, 'pt_BR');
//include "../../../../config/conexao.php";
include "../../../biblioteca/funcao.php";
extract($_GET);
?>
<html>
    
    <head>
        
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <link rel="stylesheet" type="text/css" href="../../../plugin/estilo.css">
        <link rel="stylesheet" type="text/css" href="../../../plugin/bootstrap/css/bootstrap-responsive.css">
        <link rel="stylesheet" type="text/css" href="../../../plugin/bootstrap/css/bootstrap.css"> 
        <script type="text/javascript" src="../../../plugin/jquery-1.7.2.js"></script>
        <script type="text/javascript" src="../../../plugin/bootstrap/js/bootstrap.min.js"></script>
        <script type="text/javascript" src="../../../plugin/funcao.js" /></script>

        <title>Imprimir</title>
        <link href="../../../../base/favicon.ico" rel="shortcut icon" type="image/x-icon" />
        <!-- Le HTML5 shim, for IE6-8 support of HTML5 elements -->
            <!--[if lt IE 9]>
            <script src="plugin/html5.js"></script>
        <![endif]-->
        
    </head>
    
    <body>
        
        
        <div style="padding: 20px;">
            
            <h4>Helpdesk :: Relat&oacute;rio</h4>
            <br>
            <p class="pull-right"><a href="#" onClick="window.print();"><i class="icon-print"></i> Imprimir</a></p>
            <br>
            <table class="table table-striped table-bordered table-hover" >
              <tr>
                <td><big>&Aacute;REAS DE ATUA&ccedil;&atilde;O</big></td>
                <td width="100">Aberto</td>
                <td width="100">Em Atendimento</td>
                <td width="100">Fechado</td>
                <td width="100">Reaberto</td>
                <td width="100"><big>Quantidade de Total</big></td>
              </tr>
              
              <?php
              
                $sql = "SELECT * FROM setor ORDER BY set_nome";
                $res = sql($sql);
                $i = 0;
                while($linha = mysql_fetch_array($res)){ 
                    
                    // total
                    $sql_chamado = "SELECT * FROM chamado 
                    LEFT JOIN cha_status ON cha_status.cha_sta_id=chamado.cha_status
                    WHERE set_id='{$linha['set_id']}' $onde";
                    $res_chamado = sql($sql_chamado);
                    $num_chamado = mysql_num_rows($res_chamado);
                    if ($i == 0){
                        $num_aux = $num_chamado;
                    } else {
                        $num_aux += $num_chamado;
                    }
                    
                    // aberto
                    $sql_chamado1 = "SELECT * FROM chamado 
                    LEFT JOIN cha_status ON cha_status.cha_sta_id=chamado.cha_status
                    WHERE set_id='{$linha['set_id']}' AND cha_status='1' $onde";
                    $res_chamado1 = sql($sql_chamado1);
                    $num_chamado1 = mysql_num_rows($res_chamado1);
                    if ($i == 0){
                        $num_aux_1 = $num_chamado1;
                    } else {
                        $num_aux_1 += $num_chamado1;
                    }
                    
                    // em atendimento
                    $sql_chamado2 = "SELECT * FROM chamado 
                    LEFT JOIN cha_status ON cha_status.cha_sta_id=chamado.cha_status
                    WHERE set_id='{$linha['set_id']}' AND cha_status='2' $onde";
                    $res_chamado2 = sql($sql_chamado2);
                    $num_chamado2 = mysql_num_rows($res_chamado2);
                    if ($i == 0){
                        $num_aux_2 = $num_chamado2;
                    } else {
                        $num_aux_2 += $num_chamado2;
                    }
                    
                    // fechado
                    $sql_chamado3 = "SELECT * FROM chamado 
                    LEFT JOIN cha_status ON cha_status.cha_sta_id=chamado.cha_status
                    WHERE set_id='{$linha['set_id']}' AND cha_status='3' $onde";
                    $res_chamado3 = sql($sql_chamado3);
                    $num_chamado3 = mysql_num_rows($res_chamado3);
                    if ($i == 0){
                        $num_aux_3 = $num_chamado3;
                    } else {
                        $num_aux_3 += $num_chamado3;
                    }
                    
                    // reaberto
                    $sql_chamado4 = "SELECT * FROM chamado 
                    LEFT JOIN cha_status ON cha_status.cha_sta_id=chamado.cha_status
                    WHERE set_id='{$linha['set_id']}' AND cha_status='4' $onde";
                    $res_chamado4 = sql($sql_chamado4);
                    $num_chamado4 = mysql_num_rows($res_chamado4);
                    if ($i == 0){
                        $num_aux_4 = $num_chamado4;
                    } else {
                        $num_aux_4 += $num_chamado4;
                    }

              ?>
              
              <tr>
                <td><?=$linha['set_nome'];?></td>
                <td><?=$num_chamado1?></td>
                <td><?=$num_chamado2?></td>
                <td><?=$num_chamado3?></td>
                <td><?=$num_chamado4?></td>
                <td width="70"><?=$num_chamado?></td>
              </tr>
              <?php
                $i++;
                }
                ?>
              
              <tr>
                <th>Total</th>
                <th><big><?=$num_aux_1?></big></th>
                <th><big><?=$num_aux_2?></big></th>
                <th><big><?=$num_aux_3?></big></th>
                <th><big><?=$num_aux_4?></big></th>
                <th width="70"><?=$num_aux?></th>
              </tr>
              
            </table>


    </div>
        
    </body>
    
</html>